/**
 * 自动回复Model
 * @authors 杨兴洲（of2502）
 * @date    2017/3/21 9:49
 * @version 1.0
 */

/**
 * 注意点：
 * 1. mongoose含有type字段时,需要指定typeKey: "$type",不然与默认的Schema的type冲突
 * 2. Array会默认生成_id,如果不需要_id,{_id: false}取消设置
 * 3. virtual() <==> 计算属性
 */

import {model, Schema} from "mongoose";

const ReplySchema = new Schema({
    appID: {
        "$type": String,
        "required": true
    },
    is_add_friend_reply_open: {
        "$type": Number,
        "default": 1,
        "enum": [0, 1]
    },
    is_autoreply_open: {
        "$type": Number,
        "default": 1,
        "enum": [0, 1]
    },
    add_friend_autoreply_info: {
        type: {
            "$type": String,
            "enum": ["text", "img", "voice", "video"]
        },
        content: String,
        url: String,
        title: String
    },
    message_default_autoreply_info: {
        type: {
            "$type": String,
            "enum": ["text", "img", "voice", "video"]
        },
        content: String
    },
    keyword_autoreply_info: {
        list: [{"$type": Schema.Types.ObjectId, ref: "KeywordReply"}]
    }
}, {timestamps: true, typeKey: "$type"});

ReplySchema.index({appID: 1}, {unique: 1});

const Reply = model("Reply", ReplySchema);

export default Reply;
